package 力扣日常刷题.木23一月.第20天320;

public class Demo101下一个排列 {


    public void nextPermutation(int[] nums) {
        int n = nums.length;
        if(n <= 1) return ;

        int i = n - 2,j = n - 1,k = n - 1;

        while(i >=0 && nums[i] >= nums[j]){
            j--;
            k--;
        }// 从后向前找
        if(i >= 0) {
            while(nums[i] >= nums[k]) {
                k--;
            }
            swap(nums,i,k);
        }
        reverse(nums,j,n - 1);
    }


    void swap(int[] nums,int a,int b) {
        int t = nums[a];
        nums[a] = nums[b];
        nums[b] = t;
    }

    void reverse(int[]nums,int a,int b) {
        while(a < b) {
            swap(nums,a++,b--);
        }
    }

    public static void main(String[] args) {
        System.out.println(gcd(4,8));

    }

    public static int gcd(int a,int b){
        return b == 0 ? a : gcd(b,a%b);
    }



}
